package com.example.demo.dao.people;
import com.example.demo.model.people.Customer;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
public interface CustomerDAO {
    //查询全部
    @Select("select * from customer")
    List<Customer> selectAll();

    //    添加用户
    @Insert("insert into customer(customer_name,address,telephone,zip,connectionpersion,phone,bank,account,email,fax)" +
            " values(#{customer_name},#{address},#{telephone},#{zip},#{connectionpersion},#{phone},#{bank},#{account},#{email},#{fax})")
    Integer addCustomer(Customer customer);
    //    删除用户
    @Delete("delete from customer  where customer_id=#{customer_id}")
    Integer deleteById(Integer customer_id);
    //    修改用户
    @Update("update customer set customer_name=#{customer_name},address=#{address},telephone=#{telephone},zip=#{zip},connectionpersion=#{connectionpersion},phone=#{phone},bank=#{bank},account=#{account},email=#{email},fax=#{fax} where customer_id=#{customer_id} ")
    Integer updateById(Customer customer);
    //    模糊查询
    @Select("<script>"+
            "select * from customer" +
            "<where>"+
            "<if test=\"customer_name !=null and customer_name!= ''\">"+
            "and customer_name like CONCAT('%',#{customer_name},'%')"+
            "</if>"+
            "<if test=\"connectionpersion !=null and connectionpersion != ''\">"+
            "and connectionpersion like CONCAT('%',#{connectionpersion},'%')"+
            "</if>"+
            "<if test=\"phone!=null and phone!= ''\">"+
            "and phone like CONCAT('%',#{phone},'%')"+
            "</if>"+
            "</where>"+
            "</script>")

    public List<Customer> findcustomer(String  customer_name, String connectionpersion,String phone) ;

//一对一通过ID
    @Select("select * from customer where customer_id=#{customer_id}")
    List<Customer> selectByCustomerId(Integer customer_id);

}
